package business.global.pk.tdk;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import business.global.pk.AbsPKRoundPos;
import business.global.pk.AbsPKSetRound;
import business.global.room.base.AbsRoomPos;
import business.tdk.c2s.cclass.TDK_RoundPos;
import business.tdk.c2s.cclass.TDK_SetRound;
import business.tdk.c2s.iclass.STDK_PosOpCard;
import business.tdk.c2s.iclass.STDK_PosShangFen;
import business.tdk.c2s.iclass.STDK_StartRound;
import cenum.PKOpType;
import cenum.RoomTypeEnum;
import com.ddm.server.common.utils.CommTime;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.ddm.server.websocket.handler.requset.WebSocketRequestDelegate;
import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;

/**
 * 吹牛 回合逻辑 每一次等待操作，都是一个round
 *
 * @author Huaxing
 */

public class TDKSetRound {
    // 本局信息
    protected TDKRoomSet set;
    // 房间信息
    protected TDKRoom room;
    // 回合ID
    protected int roundID;
    // 开始时间
    protected int startTime;
    // 结束时间
    protected int endTime;
    // 回合位置字典
    protected Hashtable<Integer, TDKRoundPos> roundPosDict = new Hashtable<>();
    // 是否结束本局
    protected boolean isSetHuEnd = false;
    // 是否操作出牌
    protected TDKdefine.TDK_OP opType = null;
    // 等待操作的位置
    protected int waitOpPos;
    // 回合操作信息
    private TDK_SetRound ret;

    public TDKSetRound(TDKRoomSet TDKRoomSet, int roundID) {
        this.roundID = roundID;
        this.set = TDKRoomSet;
        this.room = TDKRoomSet.getRoom();
        this.startTime = CommTime.nowSecond();
    }

    public void clean() {
        this.set = null;
        this.room = null;
        if (null != this.roundPosDict) {
            this.roundPosDict.clear();
            this.roundPosDict = null;
        }
        this.ret = null;
    }

    /**
     * 获取回合ID
     *
     * @return
     */
    public int getRoundID() {
        return roundID;
    }

    /**
     * 获取操作位置
     *
     * @return
     */
    public int getOpPos() {
        int ret = -1;
        for (int pos : this.roundPosDict.keySet()) {
            ret = pos;
            break;
        }
        return ret;
    }

    /**
     * 获取回合操作者位置
     *
     * @param opPos
     * @return
     */
    public TDKRoundPos roundPos(int opPos) {
        return this.roundPosDict.get(opPos);
    }


    /**
     * 检查是否结束本局
     *
     * @return
     */
    public boolean isSetHuEnd() {
        return isSetHuEnd;
    }

    /**
     * 设置是否结束本局
     *
     * @param isSetHuEnd
     */
    public void setSetHuEnd(boolean isSetHuEnd) {
        this.isSetHuEnd = isSetHuEnd;
    }

    /**
     * 获取本局信息
     *
     * @return
     */
    public TDKRoomSet getSet() {
        return set;
    }

    /**
     * 获取等待操作的位置
     *
     * @return
     */
    public int getWaitOpPos() {
        return waitOpPos;
    }

    /**
     * 获取操作类型
     *
     * @return
     */
    public TDKdefine.TDK_OP getOpType() {
        return opType;
    }

    /**
     * 设置操作类型
     *
     * @param opType
     */
    public void setOpType(TDKdefine.TDK_OP opType) {
        this.opType = opType;
    }

    /**
     * 获得前一轮
     *
     * @return
     */
    public TDKSetRound getPreRound() {
        if (this.roundID - 2 < 0) {
            return null;
        }
        return this.set.getHistoryRound(this.roundID - 2);
    }

    /**
     * 尝试结束回合
     */
    public void tryEndRound() {
        boolean allOp = true;

        // 遍历检查是否每个人都执行完毕了
        for (TDKRoundPos pos : this.roundPosDict.values()) {
            if (pos.getOpType() == null) {
                allOp = false;
                break;
            }
        }
        if (allOp) {
            this.endTime = CommTime.nowSecond();
        }
    }

    /**
     * 是否更新
     *
     * @param sec
     * @return
     */
    public boolean update(int sec) {
        boolean isEnd = false;
        // 已经结束
        if (this.endTime != 0) {
            if (this.endTime >= this.startTime) {
                return true;
            }
            return false;
        }

        //有开牌，1秒就开
        TDKRoundPos rPos = this.roundPos(this.getWaitOpPos());
        List<TDKdefine.TDK_OP> opList = rPos.getRecieveOpTypes();
        if (opList.contains(TDKdefine.TDK_OP.KaiPai) &&  sec - this.startTime >= 1 ) {
            this.opCard(new WebSocketRequestDelegate(), this.getWaitOpPos(), TDKdefine.TDK_OP.KaiPai, 0);
            return true;
        }

        int limit = this.set.getRoom().getXianShi();
        // 检查是否限时自动操作
        if (limit > TDKdefine.TDK_XIANSHI_TYPE.NOT.ordinal() && this.set.getShangFenPos()==-1) {
            int secLimit=this.set.getRoom().getXianShiSecond();
            if (sec - this.startTime >= secLimit) {
                // 托管操作
                if (!this.trusteeshipOp()) {
                    return false;
                }
            }
        }else if(this.set.getShangFenPos()!=-1){
            int secLimit=this.set.getRoom().getShangFenTime();
            if (sec - this.startTime >= secLimit) {
                if (!this.trusteeshipOp()) {
                    this.set.setShangFenOpTime(-1);
                    return false;
                }
            }
        }
        return isEnd;
    }

    /**
     * 托管操作
     *
     * @return
     */
    private boolean trusteeshipOp() {
        // 获取回合操作者位置
        TDKRoundPos rPos = this.roundPos(this.getWaitOpPos());
        // 检查当前回合是否存在
        if (null == rPos) {
            return false;
        }
        // 获取动作列表
        List<TDKdefine.TDK_OP> opList = rPos.getRecieveOpTypes();
        // 检查是否有动作
        if (null == opList || opList.size() <= 0) {
            return false;
        }
        int addValue = 0;
        TDKdefine.TDK_OP op = TDKdefine.TDK_OP.Not;
        if (opList.contains(TDKdefine.TDK_OP.QiPai)) {
            // 弃牌
            op = TDKdefine.TDK_OP.QiPai;
        }else if (opList.contains(TDKdefine.TDK_OP.BuTi)) {
            // 不踢
            op = TDKdefine.TDK_OP.BuTi;
        }else if (opList.contains(TDKdefine.TDK_OP.KaiPai)) {
            // 开牌
            op = TDKdefine.TDK_OP.KaiPai;
        }else {
            for (int i = 0; i < 10; i++) {
                addValue = this.set.getCurChip() + i;
                if (TDKdefine.TDK_DIFEN_TYPE.checkValueOfSet(this.set.getRoom().getDiFen(), this.set.getCurChip(), addValue, this.set.getLanguoBeishu())) {
                    break;
                }
            }
            // 押注
            op = TDKdefine.TDK_OP.YaZhu;
        }
        // 操作
        this.opCard(new WebSocketRequestDelegate(), this.getWaitOpPos(), op, addValue);
        return true;
    }


    /**
     * 托管房间POS
     *
     * @param posID
     */
    public void trusteeshipRoomPos(int posID) {
        // 是否当前操作位置
        if (posID != this.getWaitOpPos()) {
            return;
        }
        TDKSetPos waitOpPos = this.set.posDict.get(posID);
        if (null == waitOpPos) {
            return;
        }
        this.set.getRoom().getRoomPosMgr().clearPosLatelyOutCardTime(waitOpPos.getRoomPos().getPosID());
        // 获取托管状态
        if (waitOpPos.getRoomPos().isTrusteeship()) {
            // 托管操作
            //YSJVB 中途上分托管就不用管
            if(this.set.getShangFenPos()==-1){
                this.trusteeshipOp();
            }
        }

    }


    /**
     * 获取本轮信息
     *
     * @param pos 位置
     * @return
     */

    public TDK_SetRound getNotify_RoundInfo(int pos) {
        ret = new TDK_SetRound();
        ret.setWaitID(this.roundID);
        ret.setStartWaitSec(this.startTime);
        ret.setCurSystemSec(CommTime.nowSecond());
        for (TDKRoundPos roundPos : this.roundPosDict.values()) {
            // 自己 或 公开
            if (pos == roundPos.getOpPos() || roundPos.isPublicWait()) {
                TDK_RoundPos data = new TDK_RoundPos();
                data.setOpList(roundPos.getRecieveOpTypes());
                data.setWaitOpPos(roundPos.getOpPos());
                data.setAliasOpType(roundPos.getAliasOpType());
                this.waitOpPos = roundPos.getOpPos();
                ret.addOpPosList(data);
                TDKRoomPos roomPos = (TDKRoomPos) this.set.getRoom().getRoomPosMgr().getPosByPosID(this.waitOpPos);
                if (null != roomPos) {
                    this.set.getRoom().getRoomPosMgr().clearPosLatelyOutCardTime(roomPos.getPosID());
                }
                this.set.setLastShotTime(CommTime.nowSecond());
            }
        }
        return ret;
    }

    /**
     * 通知新一轮操作位置
     */
    @SuppressWarnings("rawtypes")
    public void notifyStart() {
        for (AbsRoomPos x : room.getRoomPosMgr().getAllPosList()) {
            int posID=x.getPosID();
            if (this.roundPosDict.containsKey(posID)) {
                STDK_StartRound joinner = STDK_StartRound.make(this.set.getRoom().getRoomID(), getNotify_RoundInfo(posID));
                this.set.getRoomPlayBack().playBack2Pos(x, joinner, null);
            } else {
                STDK_StartRound other = STDK_StartRound.make(this.set.getRoom().getRoomID(), getNotify_RoundInfo(-1));
                this.set.getRoom().getRoomPosMgr().notify2Pos(x, other);
            }
        }
        /*
        for (int posID = 0; posID < this.room.getPlayerNum(); posID++) {
            if (this.roundPosDict.containsKey(posID)) {
                STDK_StartRound joinner = STDK_StartRound.make(this.set.getRoom().getRoomID(), getNotify_RoundInfo(posID));
                this.set.getRoomPlayBack().playBack2Pos(posID, joinner, null);
            } else {
                STDK_StartRound other = STDK_StartRound.make(this.set.getRoom().getRoomID(), getNotify_RoundInfo(-1));
                this.set.getRoom().getRoomPosMgr().notify2Pos(posID, other);
            }
        }
        */
    }

    /**
     * 玩家操作
     *
     * @param request
     * @param opPos
     * @param opType
     * @param value
     */
    public synchronized void opCard(WebSocketRequest request, int opPos, TDKdefine.TDK_OP opType, int value) {
        if (this.endTime > 0) {
            request.error(ErrorCode.NotAllow, "endTime opPos has no round power");
            return;
        }
        TDKRoundPos pos = this.roundPosDict.get(opPos);
        if (null == pos) {
            request.error(ErrorCode.NotAllow, "opPos has no round power");
            return;
        }
        int opCardRet = pos.op(request, opType, value);
        if (opCardRet >= 0) {
            TDKSetPos setPos = set.posDict.get(opPos);
            if (null != setPos) {
                for (AbsRoomPos x : room.getRoomPosMgr().getAllPosList()) {
                    if (setPos.getPid() == x.getPid()) {
                        this.set.getRoomPlayBack().playBack2Pos(x, STDK_PosOpCard.make(this.room.getRoomID(), opPos, opType, pos.getAliasOpType(), this.set.getCurChip()), this.set.getSetPosMgr().getAllPlayBackNotify());
                    } else if (x.getPid() > 0){
                        this.set.getRoom().getRoomPosMgr().notify2Pos(x, STDK_PosOpCard.make(this.room.getRoomID(), opPos, opType,pos.getAliasOpType(),  this.set.getCurChip()));
                    }
                }
            }
        }
    }

    public void RobothandCrad(int posID) {
        TDKSetPosRobot mRobotOpCard = new TDKSetPosRobot(this);
        mRobotOpCard.RobothandCrad(posID);
    }

    /**
     * 检查是否是第1个 curOpPos此时为空
     *
     * @param pos
     * @return
     */
    private boolean checkFirstOne(int pos) {
        if (this.set.getCurOpPos() < 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 检查是否又轮到自己了。表示这一圈已经完了，是否踢
     *
     * @param pos
     * @return
     */
    private boolean checkTurnAgain(int pos) {
        if (this.set.getCurOpPos() == pos) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * 检查当前轮操作位置
     *
     * @param pos
     * @return
     */
    private boolean checkFirstOneAndTurnAgain(int pos) {
        if (this.set.getCurOpPos() < 0 || this.set.getCurOpPos() == pos) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * 开始抓牌
     *
     * @param pos
     * @return
     */
    public boolean startWithGetCard(int pos) {
        pos = this.set.doMoPaiAndGetMaxCardPos(pos);
        return this.doYaZhu(pos);
    }


    // 尝试开始回合, 如果失败，则set结束
    public boolean tryStartRound() {
        TDKSetRound preRound = getPreRound(); // 前一个可参考的操作round
        // 第一次，庄家作为操作者，抓牌，等待出牌
        if (null == preRound) {
            int opPos = this.set.getdPos();
            // 补牌
            if (!this.startWithGetCard(opPos)) {
                return false;
            }
            this.notifyStart();
            return true;
        }

        // 跟注
        if (preRound.getOpType() == TDKdefine.TDK_OP.GenZhu) {
            return tryStartRoundGenZhu(preRound);
        }
        // 开牌
        if (preRound.getOpType() == TDKdefine.TDK_OP.KaiPai) {
            return tryStartRoundGenZhu(preRound);
        }
        // 押注
        if (preRound.getOpType() == TDKdefine.TDK_OP.YaZhu
                || preRound.getOpType() == TDKdefine.TDK_OP.Ti
                || preRound.getOpType() == TDKdefine.TDK_OP.FanTi
        ) {
            return tryStartRoundGenZhu(preRound);
        }
        // 弃牌
        if (preRound.getOpType() == TDKdefine.TDK_OP.QiPai) {
            return tryStartRoundGenZhu(preRound);
        }
        // 不踢
        if (preRound.getOpType() == TDKdefine.TDK_OP.BuTi) {
            return tryStartRoundGenZhu(preRound);
        }
        return false;
    }


    protected TDKRoundPos nextRoundPos(int pos) {
        return new TDKRoundPos(this, pos);
    }

    private boolean tryStartRoundGenZhu(TDKSetRound preRound) {

        if (this.set.isAtLast()) {
            //最后一轮
            if (this.set.isTiRound()) {

                if ( preRound.getOpType() == TDKdefine.TDK_OP.BuTi && this.set.isAllTiOrBuTi()  ) {
                    if(this.set.isAllTiFu()){
                        //System.out.println("游戏结束,都已踢服");
                        return doKaiPai(preRound.getOpPos());
                    }
                }

                //下个要操作的人,
                int opPos = this.set.getCurOpPos() >= 0 ? this.set.nextOpPos(preRound.getOpPos()) : this.set.nextMoJiaoTiFuPos(preRound.getOpPos());
                if (this.set.getCurOpPos() < 0 && opPos == preRound.getOpPos()) {
                    //System.out.println("游戏结束,没人起脚================>>> opPos:" + opPos);
                    return this.doKaiPai(opPos);
                } else if (this.set.getCurOpPos() < 0) {
                    //末脚踢服没人起脚
                    //System.out.println("末脚，起脚 ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurTiPos:" + this.set.getCurOpPos());
                    return doTi(opPos);
                } else if (this.set.getCurOpPos() >= 0 && this.set.getCurOpPos() == opPos) {
                    if ( this.set.isAllTiOrBuTi()) {
                        //System.out.println("末脚，此轮都已操作 扎刀减1：" + this.set.getZhaDaoNum());
                        this.set.subZhaDaoNum();
                        //this.set.clearTiOp(opPos);

                        if(this.set.isAllTiFu()){
                            //System.out.println("游戏结束,都已踢服");
                            return doKaiPai(opPos);
                        }
                    }
                    if (this.set.getZhaDaoNum() == 0) {
                        // 开牌，表示没选末脚T服
                        //System.out.println("游戏结束 扎刀:" + this.set.getZhaDaoNum()+ ", isAllTiFu:" + this.set.isAllTiFu());
                        return doKaiPai(opPos);
                    }else{
                        //此轮出头的人，从他的下家开始
                        int curOpPos=this.set.getCurOpPos();
                        this.set.setCurOpPos(-1);
                        //去到踢服环节
                        int nextPos =this.set.nextMoJiaoTiFuPos(curOpPos);
                        //踢的只有一个人了，也结束（其他有人都服了，选了不踢）
                        if(nextPos==curOpPos){
                            return doKaiPai(opPos);
                        }
                        //System.out.println(this.set.getZhaDaoNum()+" 》 末脚，反踢， Pos：" + nextPos + ", prePos:" + preRound.getOpPos() + ", CurTiPos:" +curOpPos);
                        return doFanTi(nextPos);
                    }
                } else {
                    return this.doGenZhu(opPos);
                }
            }
            else {
                //下个要操作的人。
                int opPos = this.set.nextOpPos(preRound.getOpPos());
                //TDKSetPos setPos = this.set.posDict.get(opPos);
                //正常压注，跟注回合
                if (this.set.getCurOpPos() < 0) {
                    //正常回合,没人压注
                    //System.out.println("末脚正常回合,没人压注  ==>>>  Pos" + opPos + ", prePos:" + preRound.getOpPos() + ", CurOpPos:" + this.set.getCurOpPos());
                    //YSJVB 最大的开始
                    int maxPos = this.set.getSetPosMgr().calcNextYaPos(this.set.getUpperRoundMaxPos());
                    return doYaZhu(maxPos);
                } else if (this.set.getCurOpPos() >= 0 && this.set.getCurOpPos() == opPos) {
                    this.set.setTiRound(true);
                    this.set.setCurOpPos(-1);
                    this.set.setCurChip(0);
                    this.set.clearTiOrBuTiOp(opPos);
                    //正常回合,有人压注并且又到我了，那就是要起脚踢了
                    //System.out.println("末脚正常回合,有人压注并且又到我了，那就是要起脚踢了 ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurOpPos:" + this.set.getCurOpPos());
                    return doTi(opPos);
                } else {
                    return this.doGenZhu(opPos);
                }
            }
        }
        else {
            //正常回合
            if (this.set.isTiRound()) {
                //下个要操作的人,
                int opPos = this.set.getCurOpPos() >= 0 ? this.set.nextOpPos(preRound.getOpPos()) : this.set.nextTiPos(preRound.getOpPos());
                //TDKSetPos setPos = this.set.posDict.get(opPos);
                //是否是踢脚回合
                if (this.set.getCurOpPos() < 0 && opPos == preRound.getOpPos()) {
                    //YSJVB 2023-09-09 五人全上了，没牌了直接结束
                    if(this.set.getSetCard().getLeftCardCount()==0){
                        return this.doKaiPai(opPos);
                    }

                    //踢回合,所有人都没踢或者踢过了 那发牌
                    //System.out.println("踢回合,所有人都没踢或者踢过了，那发牌  ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurTiPos:" + this.set.getCurOpPos());
                    int pos = this.set.doMoPaiAndGetMaxCardPos(opPos);
                    return doYaZhu(pos);
                }else if (this.set.getCurOpPos() < 0) {
                    //踢回合没人起脚
                    //System.out.println("踢回合，没人起脚 ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurTiPos:" + this.set.getCurOpPos() + ", CurTiOrBuTi:" + setPos.getCurTiOrBuTi());
                    return doTi(opPos);
                } else if (this.set.getCurOpPos() >= 0 && this.set.getCurOpPos() == opPos) {
                    //踢回合,有人踢，并且又到我了，那下家选踢或者不踢
                    int nextPos = this.set.nextTiPos(opPos);
                    if (nextPos == this.set.getCurOpPos()) {
                        //YSJVB 2023-09-09 五人全上了，没牌了直接结束
                        if(this.set.getSetCard().getLeftCardCount()==0){
                            return this.doKaiPai(opPos);
                        }

                        //System.out.println("踢回合,有人踢，都踢过了：  ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurTiPos:" + this.set.getCurOpPos());
                        int pos = this.set.doMoPaiAndGetMaxCardPos(opPos);
                        return doYaZhu(pos);
                    } else {
                        //System.out.println("踢回合,有人踢，到下家了  ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurTiPos:" + this.set.getCurOpPos());
                        this.set.setCurOpPos(-1);
                        this.set.setCurChip(0);
                        return doFanTi(nextPos);
                    }
                } else {
                    return this.doGenZhu(opPos);
                }
            }
            else {
                //下个要操作的人。
                int opPos = this.set.nextOpPos(preRound.getOpPos());
                //TDKSetPos setPos = this.set.posDict.get(opPos);
                //正常压注，跟注回合
                if (this.set.getCurOpPos() < 0) {
                    //正常回合,没人压注
                    //System.out.println("正常回合,没人压注  ==>>>  Pos" + opPos + ", prePos:" + preRound.getOpPos() + ", CurOpPos:" + this.set.getCurOpPos());
                    //YSJVB 最大的开始
                    int maxPos = this.set.getSetPosMgr().calcNextYaPos(this.set.getUpperRoundMaxPos());
                    return doYaZhu(maxPos);
                } else if (this.set.getCurOpPos() >= 0 && this.set.getCurOpPos() == opPos) {
                    this.set.setTiRound(true);
                    this.set.setCurOpPos(-1);
                    this.set.setCurChip(0);
                    //正常回合,有人压注并且又到我了，那就是要起脚踢了
                    //System.out.println("正常回合,有人压注并且又到我了，那就是要起脚踢了 ==>>> Pos：" + opPos + ", prePos:" + preRound.getOpPos() + ", CurOpPos:" + this.set.getCurOpPos());
                    return doTi(opPos);
                } else {
                    return this.doGenZhu(opPos);
                }
            }
        }
    }

    private boolean doKaiPai(int opPos) {
        TDKRoundPos tmPos = this.nextRoundPos(opPos);
        tmPos.addOpType(TDKdefine.TDK_OP.KaiPai);
        tmPos.setAliasOpType(TDKdefine.TDK_OP.KaiPai);
        this.roundPosDict.put(tmPos.getOpPos(), tmPos);
        this.notifyStart();
        return true;
    }


    private boolean doFanTi(int opPos) {
        TDKRoundPos tmPos = this.nextRoundPos(opPos);
        tmPos.addOpType(TDKdefine.TDK_OP.YaZhu);
        tmPos.addOpType(TDKdefine.TDK_OP.BuTi);
        tmPos.setAliasOpType(TDKdefine.TDK_OP.FanTi);
        this.roundPosDict.put(tmPos.getOpPos(), tmPos);
        this.notifyStart();
        return true;
    }

    private boolean doTi(int opPos) {
        TDKRoundPos tmPos = this.nextRoundPos(opPos);
        tmPos.addOpType(TDKdefine.TDK_OP.YaZhu);
        tmPos.addOpType(TDKdefine.TDK_OP.BuTi);
        tmPos.setAliasOpType(TDKdefine.TDK_OP.Ti);
        this.roundPosDict.put(tmPos.getOpPos(), tmPos);
        this.notifyStart();
        return true;
    }

    private boolean doGenZhu(int pos) {
        TDKRoundPos tmPos = this.nextRoundPos(pos);
        tmPos.addOpType(TDKdefine.TDK_OP.GenZhu);
        tmPos.addOpType(TDKdefine.TDK_OP.QiPai);
        tmPos.setAliasOpType(TDKdefine.TDK_OP.GenZhu);
        this.roundPosDict.put(tmPos.getOpPos(), tmPos);
        this.notifyStart();
        this.checkGenZhuChip(pos);
        return true;
    }

    private boolean doYaZhu(int opPos) {
        TDKRoundPos tmPos = this.nextRoundPos(opPos);
        tmPos.addOpType(TDKdefine.TDK_OP.YaZhu);
        tmPos.addOpType(TDKdefine.TDK_OP.QiPai);
        tmPos.setAliasOpType(TDKdefine.TDK_OP.YaZhu);
        this.roundPosDict.put(tmPos.getOpPos(), tmPos);
        this.notifyStart();
        return true;
    }

    /**
     * 跟注检查分是否足够，不够通知上分
     * @param opPos
     */
    private void checkGenZhuChip(int opPos){
        if ( RoomTypeEnum.checkUnionOrClub(this.set.getRoom().getRoomTypeEnum())) {
            TDKSetPos setPos = this.set.posDict.get(opPos);
            AbsRoomPos roomPos= this.room.getRoomPosMgr().getPosByPosID(opPos);
            //当局消耗了的筹码
            if(roomPos.getRoomSportsPoint()-setPos.getChip()<this.set.getCurChip()){
                if(this.set.getShangFenPos()==-1){
                    this.set.setShangFenPos(setPos.getPosID());
                    this.set.setShangFenOpTime(CommTime.nowSecond());
                }
                this.set.getRoom().getRoomPosMgr().notify2All(STDK_PosShangFen.make(this.set.getRoom().getRoomID(),setPos.getPosID(),setPos.getPid(),this.set.getShangFenOpTime(),this.set.getRoom().getShangFenTime(),CommTime.nowSecond()));
            }
        }
    }

    public int getStartTime() {
        return startTime;
    }


}
